import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;


public class Dates {
		Calendar  thisDate;
		public Dates (String date) {
			thisDate = Calendar.getInstance();
			if (date != "") Str2Cal(date);
		}
		
	public  Calendar Str2Cal (String date){
		SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z", Locale.ENGLISH);
		try {
			thisDate.setTime(sdf.parse(date));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return thisDate;
	}
	public static String Cal2Str (){
		String RetStr="";
		Calendar Now=Calendar.getInstance();
		int d=Now.get(Calendar.DATE);
		int m=Now.get(Calendar.MONTH)+1;
		RetStr+=Integer.toString(Now.get(Calendar.YEAR))+"-"+(m>9?"":"0")+Integer.toString(m)+"-"+(d>9? "":"0")+Integer.toString(d);
		return RetStr;
	}
	public static int DateDiff(Calendar New, Calendar Old){
		int RetVahe=0;
		Calendar tmpCal= (Calendar) Old.clone();
		while (tmpCal.before(New)){
			tmpCal.add(Calendar.DAY_OF_MONTH, 1);
			RetVahe++;
		}
		return RetVahe;
		
	}
	public int DateDiffNow () {
		Calendar now = Calendar.getInstance();
		return DateDiff(now, thisDate);
	}
	public  int DateDiffStrNow (String Old){
		Calendar Now=Calendar.getInstance();
		return DateDiff(Now, this.Str2Cal(Old));
	}
	public  int DateDiffStr(String New, String Old){
		return DateDiff(this.Str2Cal(New), this.Str2Cal(Old));
	}
	public  boolean isLater (String Date1, String Date2){
		return this.Str2Cal(Date1).after(this.Str2Cal(Date2));
	}

}
